package drive.Controller;

import drive.Model.FavoriteRecord;
import drive.Service.ServiceInterface.FavoriteRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/favoriterecord")
public class FavoriteRecordController {
    @Autowired
    private FavoriteRecordService favoriteRecordService;

    // 查询所有收藏记录
    @GetMapping()
    public String selectAllFavoriteRecords() {
        return favoriteRecordService.findAll();
    }

    // 根据favoriteID查询收藏记录
    @GetMapping("/{favoriteID}")
    public String selectFavoriteRecordByFavoriteID(@PathVariable("favoriteID") int favoriteID) {
        return favoriteRecordService.findByFavoriteID(favoriteID);
    }

    // 根据userID查询收藏记录
    @GetMapping("/user/{userID}")
    public String selectFavoriteRecordsByUserID(@PathVariable("userID") int userID) {
        return favoriteRecordService.findByUserID(userID);
    }

    // 新增收藏记录
    @PostMapping()
    public String addFavoriteRecord(@RequestBody FavoriteRecord favoriteRecord) {
        return favoriteRecordService.add(favoriteRecord);
    }

    // 更新收藏记录
    @PutMapping()
    public String updateFavoriteRecord(@RequestBody FavoriteRecord favoriteRecord) {
        return favoriteRecordService.update(favoriteRecord);
    }

    // 删除收藏记录
    @DeleteMapping("/{favoriteID}")
    public String deleteFavoriteRecord(@PathVariable("favoriteID") int favoriteID) {
        return favoriteRecordService.delete(favoriteID);
    }
}
